package com.zhongxi.guoyuan.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;

import com.zhongxi.guoyuan.R;

/**
 * Created by qj on 2018/4/14.
 */

public class Dialogs {

    /***
     * delete item
     * @param context
     * @param position click position
     * @param handler
     * @param msgWhat
     */
    public static void deleteItemDialog(Context context, final int position, final Handler handler, final int msgWhat){
        AlertDialog dialog = new AlertDialog.Builder(context).setTitle("您确定要删除该项目吗？")
                .setPositiveButton("删除", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Message msg = Message.obtain();
                        Bundle bundle = new Bundle();
                        bundle.putInt("pos", position);
                        msg.setData(bundle);
                        msg.what = msgWhat;
                        handler.sendMessage(msg);
                        dialog.dismiss();
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(context.getResources().getColor(R.color.bg_yield));
        dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(context.getResources().getColor(R.color.bg_yield));
    }
}
